package com.hd.crdao.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hd.crdao.BuildConfig;
import com.hd.crdao.R;
import com.hd.crdao.base.BaseSecondActivity;
import com.hd.crdao.utils.SPUtils;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.view.ExpandHeadView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 *
 *@author Programming
 *@date 2017/5/19 0019
 */
public class SettingsActivity extends BaseSecondActivity {

    public AlertDialog.Builder mDialog;
    @BindView(R.id.settings_head)
    ExpandHeadView mSettingsHead;
    @BindView(R.id.mycard)
    TextView mMycard;
    @BindView(R.id.myrecommandguy)
    TextView mMyrecommandguy;
    @BindView(R.id.accountmanager)
    TextView mAccountmanager;
    @BindView(R.id.changepwd)
    TextView mChangepwd;
    @BindView(R.id.aboutus)
    TextView mAboutus;
    @BindView(R.id.logout)
    Button mLogout;
    @BindView(R.id.versionInfo)
    TextView mVersionInfo;
    public String mFlag;

    @Override
    protected void initView() {
        mFlag = getIntent().getStringExtra("flag");
        if (TextUtils.equals(mFlag, "childuser")) {
            mMycard.setVisibility(View.GONE);
            mMyrecommandguy.setVisibility(View.GONE);
            mAccountmanager.setVisibility(View.GONE);
        } else {
            mMycard.setVisibility(View.VISIBLE);
            mMyrecommandguy.setVisibility(View.VISIBLE);
            mAccountmanager.setVisibility(View.VISIBLE);
        }
        mVersionInfo.setText(String.format("版本号: V%s", BuildConfig.VERSION_NAME));
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_settings;
    }

    @Override
    protected ExpandHeadView setExpandHeadView() {
        return mSettingsHead;
    }


    @OnClick({R.id.mycard, R.id.changepwd, R.id.aboutus, R.id.logout, R.id.accountmanager, R.id.myrecommandguy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mycard:

                startActivity(new Intent(UIUtils.getContext(), MyBankCardActivity.class));
                break;
            case R.id.myrecommandguy:
                startActivity(new Intent(UIUtils.getContext(), ChangeRecommandGuyActivity.class));
                break;
            case R.id.accountmanager:
                startActivity(new Intent(UIUtils.getContext(), AccountManagerActivity.class));
                break;
            case R.id.changepwd:
                Intent intent = new Intent(UIUtils.getContext(), ForgetPwdActivity.class);
                intent.putExtra("dowhat", "changePwd");
                startActivity(intent);

                break;
            case R.id.aboutus:

                startActivity(new Intent(UIUtils.getContext(), AboutUsActivity.class));
                break;
            case R.id.logout:
                showExitDialog();
                break;
        }
    }

    public void showExitDialog() {
        mDialog = new AlertDialog.Builder(this)
                .setTitle("退出登录")
                .setMessage("您确定退出登录么？").setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SPUtils.clear();
                        SPUtils.saveString("check", "home");
                        startActivity(new Intent(UIUtils.getContext(), LoginActivity.class));
                        finish();
                    }
                }).setNegativeButton("取消", null);
        mDialog.show();
    }

    @Override
    public void onBackPressed() {
        if (TextUtils.equals(mFlag, "childuser")) {
            startActivity(new Intent(UIUtils.getContext(), ChildUserActivity.class));
            finish();
        } else {
            finish();
        }
    }
}
